package controllers
import (
	//"github.com/astaxie/beego"
	//"github.com/juusechec/jwt-beego"
	//"time"
	//"pq/models"
	//"strconv"
	//"pq/helper"
)

type AuthController struct{
	//beego.Controller
	BaseController
}

//func (this *AuthController)Register(){
//	u := this.GetString("username")
//	p := this.GetString("password")
//	r := this.GetString("repassword")
//	//e := this.GetString("email")
//	//log.Info(p,r)
//	if p == "" {
//		this.Fail("Need password","")
//	}
//	if  p != r {
//		this.Fail("Password not equal","")
//	}
//	if u == ""{
//		this.Fail("Need username","")
//	}
//	halt := helper.RandString(16)
//	user := &models.PqUser{}
//	user.Password , _ = helper.Crypt(p,halt)
//	user.Salt = halt
//	user.Type = 0
//	user.Name = u
//	user.PqTestCategoryId = 1
//	if user.Create() {
//		this.Success("注册成功!")
//	}else{
//		this.Fail("用户已存在!","")
//	}
//}
//func (this *AuthController)Login()  {
//	u := this.GetString("username")
//	p := this.GetString("password")
//	//beego.Info(u,p)
//	token := ""
//	expire := time.Now().Unix() + 86400
//	user := &models.PqUser{}
//	user.Name = u
//	//TODO : database user authorization
//	if pass,ud := user.Auth(p); pass {
//		t := jwtbeego.EasyToken{
//			Username:strconv.Itoa(ud.Id),
//			Expires:expire}
//		token,_ = t.GetToken()
//		//beego.Debug(token)
//		res := map[string]interface{}{}
//		res["access_token"] = token
//		res["expire"] = expire
//		ud.Password = ""
//		ud.Salt = ""
//		res["userinfo"] = ud
//		this.Single(res)
//	} else{
//		this.Fail("Authorization fail","")
//	}
//}

//func (this *AuthController)AdminLogin()  {
//	u := this.GetString("username")
//	p := this.GetString("password")
//	//beego.Info(u,p)
//	token := ""
//	expire := time.Now().Unix() + 86400
//	user := &models.PqUser{}
//	user.Name = u
//	//TODO : database user authorization
//	if user.AdminAuth(p)  {
//		t := jwtbeego.EasyToken{
//			Username:u,
//			Expires:expire}
//		token,_ = t.GetToken()
//		//beego.Debug(token)
//	} else{
//		this.Fail("Authorization fail","")
//	}
//	res := map[string]interface{}{}
//	res["access_token"] = token
//	res["expire"] = expire
//	this.Single(res)
//}